package anyVehicle;

import net.minecraft.src.Block;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Material;
import net.minecraft.src.Vec3D;
import net.minecraft.src.World;

import org.lwjgl.util.vector.Vector;

public abstract class BlockMovable extends Block {

	protected BlockMovable(int i, int j, Material material) {
		super(i, j, material);

	}
	

	@Override
	public boolean blockActivated(World world, int x, int y, int z, EntityPlayer entityplayer) {
		Vec3D direction = entityplayer.getLookVec().normalize();
		moveBlock(world, x, y, z, direction);
		
		return true;
		
	}

	public void moveBlock(World world, int x, int y, int z, Vec3D direction) {
		moveBlock(world, x, y, z, direction, false, false, false);
	}


	public final void moveBlock(World world, int x, int y, int z, Vec3D direction, boolean lockX, boolean lockY, boolean lockZ) {
		int newX = lockX? x : (int) Math.round(x + direction.xCoord);
		int newY = lockY? y : (int) Math.round(y + direction.yCoord);
		int newZ = lockZ? z : (int) Math.round(z + direction.zCoord);
		if (canMoveTo(world, newX, newY, newZ)) {
			int tmpID = world.getBlockId(newX, newY, newZ);
			world.setBlock(newX, newY, newZ, blockID);
			world.setBlockWithNotify(x, y, z, tmpID);
		}
	}

	protected boolean canMoveTo(World world, int newX, int newY, int newZ) {
		return world.isAirBlock(newX, newY, newZ) || !Block.blocksList[world.getBlockId(newX, newY, newZ)].isCollidable();
	}
}
